import { h } from 'vue';
import { NAvatar, NTag, NButton, NIcon } from 'naive-ui';
import { BasicColumn } from '@/components/Table';

export interface ListData {
  id: number;
  name: string;
  sex: string;
  truesex: string;
  avatar: string;
  email: string;
  city: string;
  status: string;
  type: string;
  createDate: string;
}

export interface VideoItem {
  fvid: number; // 视频唯一标识符
  user_id: number; // 用户ID
  url: string; // 视频文件的URL
  view_count: number; // 观看次数
  upload_time: string; // 上传时间
  like_count: number; // 点赞数
  favorite_count: number; // 收藏数
  comment_count: number; // 评论数
  share_count: number; // 分享数
  is_deleted: boolean; // 是否已删除
  videoSection: string; // 视频分区
  type: string; // 视频类型
  videoTitle: string; // 视频标题
  videoIntro: string; // 视频简介
  videoCover: string; // 视频封面图片URL
  videoTags: string; // 视频标签
}

const sexMap = {
  male: '男',
  female: '女',
  unknown: '未知',
};

const statusMap = {
  close: '已取消',
  refuse: '已拒绝',
  pass: '已通过',
};

// export const columns: BasicColumn<ListData>[] = [
//   {
//     title: 'id',
//     key: 'id',
//   },
//   {
//     title: '名称',
//     key: 'name',
//   },
//   {
//     title: '头像',
//     key: 'avatar',
//     render(record) {
//       return h(NAvatar, {
//         size: 50,
//         src: record.avatar,
//       });
//     },
//   },
//   {
//     title: '性别',
//     key: 'sex',
//     render(record) {
//       return h(
//         NTag,
//         {
//           type: record.sex === 'male' ? 'info' : 'error',
//         },
//         {
//           default: () => sexMap[record.sex],
//         }
//       );
//     },
//   },
//   {
//     title: '真实性别',
//     key: 'truesex',
//     render(record) {
//       return h(
//         NTag,
//         {
//           type: record.sex === 'male' ? 'info' : 'error',
//         },
//         {
//           default: () => sexMap[record.sex],
//         }
//       );
//     },
//   },
//
//   {
//     title: '邮箱',
//     key: 'email',
//     width: 220,
//   },
//   {
//     title: '城市',
//     key: 'city',
//   },
//   {
//     title: '状态',
//     key: 'status',
//     render(record) {
//       return h(
//         NTag,
//         {
//           type:
//             record.status === 'close'
//               ? 'default'
//               : record.status === 'refuse'
//                 ? 'error'
//                 : 'success',
//         },
//         {
//           default: () => statusMap[record.status],
//         }
//       );
//     },
//   },
//   {
//     title: '创建时间',
//     key: 'createDate',
//   },
// ];


export const columns: BasicColumn<VideoItem>[] = [
  {
    title: 'ID',
    key: 'fvid',
    width: 80,
  },
  {
    title: '用户ID',
    key: 'user_id',
    width: 80,
  },
  {
    title: '视频URL',
    key: 'url',
    width: 200,
    render(record) {
      return record.url;
    },
  },
  {
    title: '观看次数',
    key: 'view_count',
    width: 100,
  },
  {
    title: '上传时间',
    key: 'upload_time',
    width: 180,
  },
  {
    title: '点赞数',
    key: 'like_count',
    width: 100,
  },
  {
    title: '收藏数',
    key: 'favorite_count',
    width: 100,
  },
  {
    title: '评论数',
    key: 'comment_count',
    width: 100,
  },
  {
    title: '分享数',
    key: 'share_count',
    width: 100,
  },
  {
    title: '是否已删除',
    key: 'is_deleted',
    width: 100,
  },
  {
    title: '视频分区',
    key: 'videoSection',
    width: 120,
  },
  {
    title: '视频类型',
    key: 'type',
    width: 100,
  },
  {
    title: '视频标题',
    key: 'videoTitle',
    width: 200,
  },
  {
    title: '视频简介',
    key: 'videoIntro',
    width: 200,
  },
  {
    title: '视频封面',
    key: 'videoCover',
    width: 100,
    render(record) {
      return h(NAvatar, {
        size: 50,
        src: record.videoCover,
      });
    },
  },
  {
    title: '视频标签',
    key: 'videoTags',
    width: 150,
  },
];

// 文章数据接口定义
export interface ArticleData {
  articleID: number;
  authorID: number;
  title: string;
  content: string;
  likeCount: number;
  favoriteCount: number;
  commentCount: number;
  creationTime: Date;
  recommendationIndex: number;
  longitude: number;
  latitude: number;
  tag: string;
  status: 'draft' | 'published' | 'pendingReview' | 'deleted';
}

// 文章状态映射
const articleStatusMap = {
  draft: '草稿',
  published: '已发布',
  pendingReview: '待审核',
  deleted: '已删除',
};

// 状态标签类型映射
const articleStatusTypeMap = {
  draft: 'default',
  published: 'success',
  pendingReview: 'warning',
  deleted: 'error',
};

// 文章列定义
export const articleColumns: BasicColumn<ArticleData>[] = [
  {
    title: '文章ID',
    key: 'articleID',
    width: 80,
  },
  {
    title: '作者ID',
    key: 'authorID',
    width: 80,
  },
  {
    title: '标题',
    key: 'title',
    width: 200,
  },
  {
    title: '内容预览',
    key: 'content',
    width: 300,
    render(record) {
      // 内容预览，只显示前50个字符
      return record.content.length > 50 
        ? record.content.substring(0, 50) + '...' 
        : record.content;
    },
  },
  {
    title: '点赞数',
    key: 'likeCount',
    width: 80,
  },
  {
    title: '收藏数',
    key: 'favoriteCount',
    width: 80,
  },
  {
    title: '评论数',
    key: 'commentCount',
    width: 80,
  },
  {
    title: '创建时间',
    key: 'creationTime',
    width: 150,
    render(record) {
      return new Date(record.creationTime).toLocaleString();
    },
  },
  {
    title: '推荐指数',
    key: 'recommendationIndex',
    width: 80,
  },
  {
    title: '标签',
    key: 'tag',
    width: 120,
    render(record) {
      return h(
        NTag,
        {
          type: 'info',
        },
        {
          default: () => record.tag,
        }
      );
    },
  },
  {
    title: '状态',
    key: 'status',
    width: 100,
    render(record) {
      return h(
        NTag,
        {
          type: articleStatusTypeMap[record.status] as any,
        },
        {
          default: () => articleStatusMap[record.status],
        }
      );
    },
  },
];

// 举报记录数据接口定义
export interface ReportData {
  reportID: number;
  reporterID: number;
  reporteeID: number;
  reportType: 'article' | 'item';
  reportReason: string;
  handlingResult: string;
  submissionTime: string;
  handlingTime: string;
  reportStatus: 'pending' | 'handled';
}

// 举报类型映射
const reportTypeMap = {
  article: '文章',
  item: '物品',
};

// 举报状态映射
const reportStatusMap = {
  pending: '待处理',
  handled: '已处理',
};

// 状态类型映射
const reportStatusTypeMap = {
  pending: 'warning',
  handled: 'success',
};

export const reportColumns: BasicColumn<ReportData>[] = [
  {
    title: '举报ID',
    key: 'reportID',
    width: 80,
  },
  {
    title: '举报人ID',
    key: 'reporterID',
    width: 100,
  },
  {
    title: '被举报人ID',
    key: 'reporteeID',
    width: 100,
  },
  {
    title: '举报类型',
    key: 'reportType',
    width: 100,
    render(record) {
      return h(
        NTag,
        {
          type: 'info',
        },
        {
          default: () => reportTypeMap[record.reportType],
        }
      );
    },
  },
  {
    title: '举报原因',
    key: 'reportReason',
    width: 300,
    render(record) {
      // 内容预览，只显示前50个字符
      return record.reportReason.length > 50 
        ? record.reportReason.substring(0, 50) + '...' 
        : record.reportReason;
    },
  },
  {
    title: '提交时间',
    key: 'submissionTime',
    width: 180,
    render(record) {
      return new Date(record.submissionTime).toLocaleString();
    },
  },
  {
    title: '状态',
    key: 'reportStatus',
    width: 100,
    render(record) {
      return h(
        NTag,
        {
          type: reportStatusTypeMap[record.reportStatus] as any,
        },
        {
          default: () => reportStatusMap[record.reportStatus],
        }
      );
    },
  },
];
